﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace 实验二._3
{
    class Program
    {
        static void Main(string[] args)
        {
            try//尝试创建triangle1
            {
                Triangle t1 = new Triangle(1, 1, 3, "triangle1");
                Console.WriteLine($"{t1.Id}创建成功！");
                Console.WriteLine($"{t1.Id}的面积为：{t1.Area()}");
                Console.WriteLine($"{t1.Id}的周长为：{ t1.Perimeter()}");

            }
            catch (ArgumentException)//捕捉异常
            {

                Console.WriteLine("创建失败，无法计算面积和周长！");
            }
            try//尝试创建triangle2
            {
                Triangle t2 = new Triangle(1, 1, 1, "triangle2");
                Console.WriteLine($"{t2.Id}创建成功！");
                Console.WriteLine($"{t2.Id}的面积为：{t2.Area()}");
                Console.WriteLine($"{t2.Id}的周长为：{ t2.Perimeter()}");
            }
            catch (ArgumentException)//捕捉异常
            {

                Console.WriteLine("创建失败，无法计算面积和周长！");
            }
            Console.ReadKey();

        }
    }
    class Triangle
    {
        private int a;
        private int b;
        private int c;
        private string id;
        public int A { get { return a; } set { a = value; } }
        public int B { get { return b; } set { b = value; } }
        public int C { get { return c; } set { c = value; } }

        public string Id { get { return id; } set { id = value; } }

        public Triangle(int a, int b, int c, string id)
        {
            A = a;
            B = b;
            C = c;
            if (c <= 0 | a <= 0 | b <= 0 | (a + b) < c | (a + c) < b | (b + c) < a)
            {
                throw new ArgumentException();//抛出异常

            }
            Id = id;
        }
        public int Perimeter()//计算周长
        {
            return (a + b + c);
        }
        public float Area()//计算面积
        {
            float p = (float)(1.0 / 2 * (a + b + c));
            return (float)Math.Sqrt(p * (p - a)) * (p - b) * (p - c);
        }
    }
}
